package com.congee02;

import java.util.Arrays;

public class UniquePaths_TL {

    public int uniquePaths(int m, int n) {
        for (int[] c : cache) {
            Arrays.fill(c, -1);
        }
        return process(m, n, 1, 1);
    }

    int[][] cache = new int[101][101];
    private int process(int m, int n, int x, int y) {
        if (x > m || y > n) {
            return 0;
        }
        if (x == m && y == n) {
            return 1;
        }
        if (cache[x][y] == -1) {
            cache[x][y] = process(m, n, x + 1, y) + process(m, n, x, y + 1);
        }
        return cache[x][y];
    }


}
